﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Web.UI.WebControls;
using System.Data;
using System.Reflection;
using System.Collections;

/// <summary>
/// Summary description for DALService
/// </summary> 
[System.ComponentModel.DataObject]
public class DALService
{
    /// <summary>
    /// The list service information currently provided by Post office
    /// </summary>
    /// <returns>List of Service</returns>
    [System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
    public static List<Service> ListService()
    {
       return DAL.GetDataItems<Service>(SQL.ListService, new string[] {}, new object[] {});
    }

    /// <summary>
    /// Update specific information of service based on ServiceID
    /// </summary>
    /// <param name="ServiceName">The service's name</param>
    /// <param name="ServiceImage">The service's image</param>
    /// <param name="Description">The service's description</param>
    /// <param name="ServiceID">The service's id</param>
    /// <returns>Update successful or not</returns>
    public static bool UpdateService(string ServiceName,string ServiceImage,string Description,string ServiceID)
    {
        try
        {
            SqlCommand cmd = DAL.CreateCommand();

            SqlParameter param = new SqlParameter("@ServiceName", SqlDbType.NVarChar);
            param.Size = 100;
            param.Value = ServiceName;
            cmd.Parameters.Add(param);

            param = new SqlParameter("@ServiceImage", SqlDbType.NVarChar);
            param.Size = 200;
            param.Value = ServiceImage;
            cmd.Parameters.Add(param);

            param = new SqlParameter("@Description", SqlDbType.NVarChar);
            param.Size = 1000;
            param.Value = Description;
            cmd.Parameters.Add(param);

            param = new SqlParameter("@ServiceID", SqlDbType.Int);
            param.Value = ServiceID;
            cmd.Parameters.Add(param);

            cmd.CommandText = SQL.UpdateService;
            if (DAL.ExecuteNonQuery(cmd) > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch 
        {
            return true;
        }
        
    }

    /// <summary>
    /// Add information of service 
    /// </summary>
    /// <param name="ServiceName">The service's name</param>
    /// <param name="ServiceImage">The service's image</param>
    /// <param name="Description">The service's description</param>
    /// <returns>Add successful or not</returns>
    public static bool AddService(string ServiceName, string ServiceImage, string Description)
    {
        SqlCommand cmd = DAL.CreateCommand();
        cmd.Parameters.AddWithValue("@ServiceName",ServiceName);
        cmd.Parameters.AddWithValue("@ServiceImage", ServiceImage);
        cmd.Parameters.AddWithValue("@Description", Description);
        cmd.CommandText = SQL.AddService;
        if (DAL.ExecuteNonQuery(cmd) > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// Delete specific information of service based on service id
    /// </summary>
    /// <param name="ServiceID">The service's id</param>
    /// <returns>Delete successful or not</returns>
    public static bool DeleteService(string ServiceID)
    {
        SqlCommand cmd = DAL.CreateCommand();
        cmd.Parameters.AddWithValue("@ServiceID", ServiceID);
        cmd.CommandText = SQL.DeleteService;
        if (DAL.ExecuteNonQuery(cmd) > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    /// <summary>
    /// View specific information of service based on service id
    /// </summary>
    /// <param name="ServiceID">The service's id</param>
    /// <returns>entity service</returns>
    public static Service SelectedService(string ServiceID)
    {
        return DAL.GetDataItem<Service>(SQL.SelectedService, new string[] { "@ServiceID"}, new object[] { ServiceID});
    }

    /// <summary>
    /// Check Selected Service By ServiceID
    /// </summary>
    /// <param name="ServiceID"></param>
    /// <returns>True : Continue</returns>
    /// <returns>False : Redirect To ViewService.aspx</returns>
    public static bool CheckService(string ServiceID)
    {
        if (DAL.GetDataItems<Service>(SQL.SelectedService, new string[] { "@ServiceID" }, new object[] { ServiceID }).Count>0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
